﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crosland.Framework.DataHelper;
using Crosland.Framework.Base;
using Crosland.Offline.Core;
using Crosland.Offline.Data.Helper;
using System.Data.Common;
using System.Data;

namespace Crosland.Offline.Data.Dao
{
    public class UbigeoDao : DaoBase
    {
        public UbigeoDao(string strConn)
            : base(strConn)
        {
        }

        UbigeoHelper helper = new UbigeoHelper();

        public List<Ubigeo> List()
        {
            List<Ubigeo> entitys = new List<Ubigeo>();
            DbCommand command = dbProvider.GetStoredProcCommand(helper.SpList);

            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    entitys.Add(helper.Create(dr));
                }
            }

            return entitys;
        }

        public DataSet GetByListRegion()
        {
            DataSet ds = new DataSet();
            DbCommand command = dbProvider.GetStoredProcCommand("USP_LIST_REGION");

            dbProvider.LoadDataSet(command, ds, "ListaRegion");

            return ds;
        }

        public DataSet GetByCriteriaPoblacion(string IdRegion)
        {
            DataSet ds = new DataSet();
            DbCommand command = dbProvider.GetStoredProcCommand("USP_LIST_POBLACION");
            dbProvider.AddInParameter(command, helper.IdRegion, DbType.String, IdRegion);

            dbProvider.LoadDataSet(command, ds, "ListaPoblacion");

            return ds;
        }

        public DataSet GetByCriteriaDistrito(string IdPoblacion)
        {
            DataSet ds = new DataSet();
            DbCommand command = dbProvider.GetStoredProcCommand("USP_LIST_DISTRITO");
            dbProvider.AddInParameter(command, helper.IdPoblacion, DbType.String, IdPoblacion);

            dbProvider.LoadDataSet(command, ds, "ListaDistrito");

            return ds;
        }
    }
}
